package com.china08.yxyapi.api.manage.tec.teaching.homework.worklist.workinfo.detail;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.homework.HomeworkTaskQues;
import com.china08.yxyapi.entity.mg.homework.HomeworkTaskQues.Article;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskQuesRepository;
import com.china08.yxyapi.service.manage.tec.teaching.homework.ElasticQuesService;

/**
 * 作业详情-阅读类
 */
@CrossOrigin
@RestController
public class HomeworkDetailQues5Controller extends YxyApiBaseController {

    @Autowired
    HomeworkTaskQuesRepository homeworkTaskQuesRepository;

    @Autowired
    ElasticQuesService elasticQuesService;

    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/tec/teaching/homework/worklist/workinfo/detail/ques5/get", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(//
            HttpServletRequest request, //
            HttpServletResponse response, //
            @RequestParam String taskId, //
            RespModel respModel) throws ParseException {

        // 获得作业试题的 阅读类试题
        HomeworkTaskQues homeworkTaskQues = homeworkTaskQuesRepository.findTop1ByTaskIdAndQuesType(taskId, "5");
        if (homeworkTaskQues != null) {
            respModel.quesId = homeworkTaskQues.getQuesId();
            respModel.quesArticle = homeworkTaskQues.getQuesArticle();
        }
        return respModel;
    }

    /** 响应 **/
    protected static class RespModel extends YxyApiRespModel {
        // 试题Id
        public String quesId = null;
        // quesArticle
        public List<Article> quesArticle = new ArrayList<Article>();
    }
}